<template>
	<view>
		<view class="title">订单详情</view>
		<view class="flex orderlist">
		
			<view class="flex-grow-1" >
				<view class="num">
					面值 : {{info.money}}
				</view>
				<view class="num">
					剩余次数 : {{info.number-info.use_num}}/{{info.number}}
				</view>
				<view class="price">
					订单总价 : ￥{{info.total_money}}
				</view>
			</view>

		</view>
		<view class="subtitle">订单详情</view>

		<view class="ordernum">
			<view>订单号</view>
			<view class="num"> {{info.order_no}}</view>
		</view>
		<view class="ordernum">
			<view>支付状态</view>
			<view class="num"> {{info.is_pay == 1 ? '已支付' : '未支付'}}</view>
		</view>
		<view class="ordernum">
			<view>下单时间</view>
			<view class="num"> {{info.createtime}}</view>
		</view>
		<view class="ordernum" v-if="info.usetime">
			<view>核销时间</view>
			<view class="num"> {{info.usetime}}</view>
		</view>
	
		<view class="bottom-box">
			<button class="hexiao-btn" @click="hexiaoTap()" v-if="info.status == 1||info.status == 2">确认核销</button>
			<button class="hexiao-btn"  v-else>已核销</button>
		</view>
	</view>
</template>

<script>
	import {Store} from '../../../apirequest/store-model.js';
	var s = new Store();
	export default {
		data() {
			return {
				order_id:0,
				info:{}
			}
		},
		onLoad(options) {
			if(options.order_id){
				this.order_id = options.order_id
			}
			
			if(options.scene){
				 console.log(options)
				 var options = decodeURIComponent(options.scene)
				 console.log(options)
				 var arr = options.split(':');
				 this.order_id = arr[1]
				 
			}
			this._index();
		},
		methods: {
			_index(){
				var that = this;
				s.hexiao_info({order_id:this.order_id},(res) => {
					if(res.code == 1){
						that.info = res.data
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			},
			hexiaoTap: function() {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认核销',
					success: function(res) {
						if (res.confirm) {
							s.hx({order_id:that.order_id},(r) => {
								uni.showToast({
									title:r.msg,
									icon:'none'
								})
								if(r.code == 1){
									setTimeout(() => {
										uni.redirectTo({
											url:"/pages/shop/user/user"
										})
									},1000)
								
								}
							})	
						} else if (res.cancel) {

						}
					}
				});
			}
		}
	}
</script>

<style>
	page {
		background: #eee;
		font-size: 0.85rem;
		color: #333;
	}

	.title {
		background: #fff;
		text-align: center;
		font-size: 1rem;
		padding: 20rpx 0;
	}

	.orderlist {
		background: #fff;
		padding: 20rpx;
	}

	.orderlist .num {
		color: #999;
		margin-top: 20rpx
	}

	.orderlist .price {
		color: #FF4645;
		margin-top: 20rpx;
	}

	.orderlist .flex-grow-0 {
		margin-right: 20rpx;
	}

	.subtitle {
		padding: 16rpx 20rpx;
		color: #565656;
	}

	.ordernum {
		background: #fff;
		padding: 16rpx 20rpx;
		line-height: 40rpx;
	}

	.ordernum .num {
		color: #898989;
	}

	.bottom-box {
		background: #fff;
		text-align: center;
		padding: 60rpx 0;
	}

	.bottom-box .time {
		color: #898989;
	}

	.bottom-box .hexiao-btn {
		background: #1576fb;
		color: #fff;
		border-radius: 40rpx;
		font-size: 0.95rem;
		width: 80%;
		margin: 40rpx auto 0;
	}
</style>
